﻿using System;
using System.Diagnostics.Contracts;

namespace Server.EventHandlers
{
    /// <summary>
    /// Provides data for an exception related event.
    /// </summary>
    public sealed class ExceptionEventArgs : EventArgs
    {
        #region Fields

        /// <summary>
        /// The <see cref="T:System.Exception" /> that represents the error that occured.
        /// </summary>
        private readonly Exception m_exception;

        #endregion

        #region Properties

        /// <summary>
        /// Gets the <see cref="T:System.Exception" /> that represents the error that occured.
        /// </summary>
        public Exception Exception
        {
            get
            {
                Contract.Ensures(Contract.Result<Exception>() != null);

                return m_exception;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="T:Server.EventHandlers.ExceptionEventArgs" /> class.
        /// </summary>
        /// <param name="exception">The <see cref="T:System.Exception" /> that represents the error that occured.</param>
        public ExceptionEventArgs(Exception exception)
        {
            Contract.Requires<ArgumentNullException>(exception != null);

            m_exception = exception;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Define the invariant valid state for this class.
        /// </summary>
        [ContractInvariantMethod]
        private void InvariantValidState()
        {
            Contract.Invariant(m_exception != null);
        }

        #endregion
    }
}
